#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@author: lyndon
@time Created on 2019/2/21 14:38
@desc
"""

from urlparse3.urlparse3 import parse_url

def getconninfo(login_str):
    db_infos = {}
    dbtype, dbinfo = login_str.split("://")
    loginInfo, hostInfo = dbinfo.split('@')
    userName, passWord = loginInfo.split(':')
    hostInfo, dataBase = hostInfo.split('/')
    host, port = hostInfo.split(':')
    db_infos.setdefault('dbtype', dbtype)
    db_infos.setdefault('username', userName)
    db_infos.setdefault('password', passWord)
    db_infos.setdefault('host', host)
    db_infos.setdefault('port', port)
    db_infos.setdefault('database', dataBase)
    return db_infos


def getconninfo2(login_str):
    db_infos = parse_url(url).__dict__
    db_infos['dbtype'] = db_infos.pop('scheme')
    db_infos['host'] = db_infos.pop('domain')
    db_infos['database'] = db_infos.pop('path').replace('/', '')
    db_infos.pop('query')
    db_infos.pop('fragment')
    return db_infos


url = "https://127.0.0.1/oauth/authorize" \
      "?redirect_uri=https%3A%2F%2Fopen.bot.tmall.com%2Foauth%2Fcallback%3FskillId%3D18936%26token%3DNzkzODU4MzM3QUZFSElORkRWUQ%3D%3D" \
      "&client_id=o92cvMIa5FzGbq4LpHJoaf2j" \
      "&response_type=code" \
      "&state=0.1354064097905866"

dest_str = parse_url(url)
print(dest_str.__dict__)

url = 'sqlalchemy+mysql+resultdb://result_test:result_test_1Q#@192.168.100.161:3306/result_test_db'
sqlalchemy_url = parse_url(url)
print(sqlalchemy_url.__dict__)

pa = sqlalchemy_url.path
db = pa.replace('/', '')
print(db)

dd_dc = getconninfo(url)
print(dd_dc)

d = getconninfo2(url)
print(d)

# error
# jdbcUrl='jdbc:mysql://192.168.100.161:3306/result_test_db?characterEncoding=utf8'
# jdbcUrl_dict = urlparse1(jdbcUrl)
# print(jdbcUrl_dict)
# print(jdbcUrl_dict.__dict__)
import re
targetPath = '/home/spd/ddd'
sepinPath = re.findall(r'/', targetPath)
print(sepinPath)
if not len(sepinPath):
      print(1)
else:
      print(2)